
import { _decorator, Component, Sprite, SpriteFrame } from "cc";
import I18nManager, { LanguageType } from "./I18nManager";


const { ccclass, property } = _decorator;

@ccclass
export default class I18nSprite extends Component {

    @property({ type: SpriteFrame, visible() { return I18nManager.instance.isSupportLanguage(LanguageType.en); }, displayName: '英语 / en' })
    enFrame: SpriteFrame = null;

    @property({ type: SpriteFrame, visible() { return I18nManager.instance.isSupportLanguage(LanguageType.ko); }, displayName: '韩语 / ko' })
    koFrame: SpriteFrame = null;

    @property({ type: SpriteFrame, visible() { return I18nManager.instance.isSupportLanguage(LanguageType.ko); }, displayName: '日语 / ja' })
    jaFrame: SpriteFrame = null;

    onLoad() {
        this.switchLanguage(I18nManager.instance.language);
        I18nManager.instance.registerSprite(this);
    }

    public switchLanguage(type: LanguageType) {
        switch (type) {
            case LanguageType.ko:
                this.getComponent(Sprite).spriteFrame = this.koFrame || this.enFrame;
                break;
            case LanguageType.ja:
                this.getComponent(Sprite).spriteFrame = this.jaFrame || this.enFrame;
                break;
            default:
                this.getComponent(Sprite).spriteFrame = this.enFrame;
                break;
        }
    }
}
